#include "../../common/detail.hpp"
#include "../../server/rpc_server.hpp"

void Add(const Json::Value &req, Json::Value &rsp)
{
    int num1 = req["num1"].asInt();
    int num2 = req["num2"].asInt();
    rsp = num1 + num2;
}
int main()
{
    // // 创建Dispatcher对象
    // auto dispatcher = std::make_shared<tmh_rpc::Dispatcher>();
    // auto router = std::make_shared<tmh_rpc::server::RpcRouter>();

    std::unique_ptr<tmh_rpc::server::SDescribeFactory> desc_factory(new tmh_rpc::server::SDescribeFactory());
    desc_factory->setMethodName("Add");
    desc_factory->setParamsDesc("num1", tmh_rpc::server::VType::INTEGRAL);
    desc_factory->setParamsDesc("num2", tmh_rpc::server::VType::INTEGRAL);
    desc_factory->setReturnType(tmh_rpc::server::VType::INTEGRAL);
    desc_factory->setCallback(Add);
    // router->registerMethod(desc_factory->build());

    // auto cb = std::bind(&tmh_rpc::server::RpcRouter::onRpcRequest, router.get(), std::placeholders::_1, std::placeholders::_2);
    
    // dispatcher->registerHandler<tmh_rpc::RpcRequest>(tmh_rpc::MType::REQ_RPC, cb); // 注册消息类型和回调的映射关系

    // // 创建MuduoServer对象,并且指定端口9090
    // auto server = tmh_rpc::ServerFactory::create(9090);

    // auto message_cb = std::bind(&tmh_rpc::Dispatcher::onMessage, dispatcher.get(), std::placeholders::_1, std::placeholders::_2);
    // server->setMessageCallback(message_cb);
    tmh_rpc::Address addr={"127.0.0.1",8080};

    //不启用服务注册功能
    tmh_rpc::server::RpcServer server(addr);

    //将当前提供的服务注册进内部管理模块
    server.registerMethod(desc_factory->build());
    server.start();
    return 0;
}